package com.example.springbootlucenedemo.http;

import com.example.springbootlucenedemo.bean.TbUsersInfo;
import com.example.springbootlucenedemo.common.lucene.IndexService;
import com.example.springbootlucenedemo.service.impl.TbUsersInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("lucene")
public class LuceneController {
    @Autowired
    TbUsersInfoServiceImpl tbUsersInfoService;
    @Autowired
    IndexService indexService;


    @GetMapping("/init/tbUsersInfo")
    public void initTbUsersInfo(){
        int pageSize = 10000;
        long c= (tbUsersInfoService.tbUsersInfoDao.count() / pageSize) + 1L;
        for (int i = 0; i < 2; i++) {
            Pageable pageable = PageRequest.of(i,pageSize);
            Page<TbUsersInfo> page = tbUsersInfoService.tbUsersInfoDao.findAll(pageable);
            indexService.addDocument(page.getContent());
            System.out.println("第"+i+"页");
        }
    }




}
